package com.generator.collet.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.generator.collet.entity.SchEventEvalEntity;
import com.generator.collet.mapper.SchEventEvalMapper;
import com.generator.collet.service.ISchEventEvalService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 班级大事件 服务实现类
 * </p>
 *
 * @author tiankun
 * @since 2023-06-09
 */
@Service
public class SchEventEvalServiceImpl extends ServiceImpl<SchEventEvalMapper, SchEventEvalEntity> implements ISchEventEvalService {

    public static void main(String[] args) {
        // 创建实体类集合
        List<Entity> entityList = new ArrayList<>();
        entityList.add(new Entity("value3", "entity3"));
        entityList.add(new Entity("value1", "entity1"));
        entityList.add(new Entity("value2", "entity2"));
        entityList.add(new Entity("value4", "entity4"));

        // 创建需要排序的字段的顺序列表
        List<String> orderList = Arrays.asList("value1", "value3", "value4");

        // 对实体类集合进行排序
        List<Entity> sortedEntityList = entityList.stream()
                .sorted(Comparator.comparing(entity -> orderList.indexOf(entity.getField()) == -1 ? 99 : orderList.indexOf(entity.getField())))
                .collect(Collectors.toList());

        // 输出排序后的实体类集合
        sortedEntityList.forEach(entity -> System.out.println(entity.getField() + " " + entity.getName()));
    }


    static class Entity {
        private String field;
        private String name;

        public Entity(String field, String name) {
            this.field = field;
            this.name = name;
        }

        public String getField() {
            return field;
        }

        public void setField(String field) {
            this.field = field;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

}
